/*declare @Precio float, @id int, @res float, @nombre varchar(100)
declare qPrecio Cursor for

	select ListPrice, ProductID, Name
	from Production.Product

open qPrecio
Fetch next from qPrecio into @Precio, @id, @nombre
while @@FETCH_STATUS = 0
begin
select @res =
	case 
		 when  @Precio < = 100 then 
		     

			  @Precio + 0.15 * @Precio
  
			 
		 when  @Precio > 100 then
		   
		      @Precio + 0.1 * @Precio
			  
		 /*when  @Precio ISNULL
		 
			 RaiseError ('No existe un precio para este producto',10,1)
		 */
	 End 

	 declare @Temp table (Nombre varchar(100), PrecioInicial float ,Incremento Float, PrecioActual float )

	 update Production.Product
	 set ListPrice = @res
	 output @nombre, deleted.ListPrice ,@res-@Precio,inserted.ListPrice
	 into @Temp (Nombre,PrecioInicial,Incremento,PrecioActual) 
	 where ProductID = @id

	 insert into Production.ProductListPriceHistory
	 values (@id,CURRENT_TIMESTAMP,DATEADD(YEAR,1,CURRENT_TIMESTAMP),@res,CURRENT_TIMESTAMP)

	 fetch next from qPrecio into @Precio,@id, @nombre
end
close qPrecio
Deallocate qPrecio 

select * from Production.Product
select * from Production.ProductListPriceHistory
select * from @Temp*/

-- 2 --




declare @aux int, @aux2 int
create table #temp (numero int) 
set @aux = 0
set @aux2 = 1
insert into #temp values (@aux)

while @aux2 < 30000

begin 

insert into #temp values (@aux2+@aux)

set @aux = @aux2
set @aux2 = (select max(numero) from #temp)

end


merge into northwnd.dbo.customers AS tgt
using(
		select p.businessEntityID as 'id',P.FirstName + P.LastName as 'Nombre'
			from person.person as p
			join #temp as t on p.businessEntityID = t.numero
			 
	  ) As src on src.id = tgt.CustomerID 

when matched then update set
  tgt.ContactName = src.Nombre

when not matched then insert(CustomerID,ContactName)
	values(src.id,src.Nombre);


drop table  #temp